package cliente;

public class IU_ConexaoRemota extends javax.swing.JFrame {

    // Inicialização de instância única de
    private static final IU_ConexaoRemota theIU_ConexaoRemota = new IU_ConexaoRemota();

    // Construtor privado
    private IU_ConexaoRemota(){
        initComponents();
    }

    // Ponto de acesso à instância única
    public static IU_ConexaoRemota getIU_ConexaoRemota(){
        return theIU_ConexaoRemota;
    }
    
    public void exibirTela(){
        getIU_ConexaoRemota().setVisible(true);
    }
    
    public void ocultarTela(){
        getIU_ConexaoRemota().setVisible(false);
    }
    
    public void fecharTela(){
        getIU_ConexaoRemota().dispose();
    }
    
    public void informarNomeEIP(String nome, String ip){
        /* Chamado por: Jogador
         * Caso de uso: Entrar em Sala, VF1 */
        this.coletarNomeDeJogador(nome);
        this.coletarIpDoServidor(ip);
    }

    private void coletarNomeDeJogador(String nome){
        /* Chamado por: IU_ConexaoRemota
         * Caso de uso: Entrar em Sala, VF1 */
        RN_Jogador.getRN_Jogador().setNome(nome);
    }
    
    private void coletarIpDoServidor(String ip){
        /* Chamado por: IU_ConexaoRemota
         * Caso de uso: Entrar em Sala, VF1 */
        SO_PresidenteCliente.getSO_PresidenteCliente().setIp("rmi://"+ip.trim()+":1099/PresidenteServidor");
        SO_PresidenteCliente.getSO_PresidenteCliente().conectarSeAoServidor();
    }
    
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        campoIPDoServidor_ConexaoRemota = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        campoNomeDoJogador_ConexaoRemota = new javax.swing.JTextField();
        botaoSair_ConexaoRemota = new javax.swing.JButton();
        botaoConectar_ConexaoRemota = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setTitle("Conexao Remota");
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        setName("frame_ConexaoRemota"); // NOI18N
        setResizable(false);

        jPanel1.setBackground(new java.awt.Color(51, 153, 0));

        jLabel1.setForeground(new java.awt.Color(255, 255, 255));
        jLabel1.setText("Nome do Jogador");

        jLabel2.setForeground(new java.awt.Color(255, 255, 255));
        jLabel2.setText("IP do Servidor");

        botaoSair_ConexaoRemota.setText("Sair");
        botaoSair_ConexaoRemota.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoSair_ConexaoRemotaActionPerformed(evt);
            }
        });

        botaoConectar_ConexaoRemota.setText("Conectar");
        botaoConectar_ConexaoRemota.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoConectar_ConexaoRemotaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(24, 24, 24)
                        .addComponent(campoNomeDoJogador_ConexaoRemota, javax.swing.GroupLayout.DEFAULT_SIZE, 395, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addGap(18, 18, 18)
                        .addComponent(campoIPDoServidor_ConexaoRemota, javax.swing.GroupLayout.DEFAULT_SIZE, 420, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(botaoConectar_ConexaoRemota)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(botaoSair_ConexaoRemota)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(campoNomeDoJogador_ConexaoRemota, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(campoIPDoServidor_ConexaoRemota, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(botaoSair_ConexaoRemota)
                    .addComponent(botaoConectar_ConexaoRemota))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void botaoSair_ConexaoRemotaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoSair_ConexaoRemotaActionPerformed
    fecharTela();
    IU_Inicial.getIU_Inicial().habilitarTela();
    IU_Inicial.getIU_Inicial().exibirTela();
    IU_Inicial.getIU_Inicial().habilitarBotaoConexaoRemota();
}//GEN-LAST:event_botaoSair_ConexaoRemotaActionPerformed

private void botaoConectar_ConexaoRemotaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoConectar_ConexaoRemotaActionPerformed
    informarNomeEIP(campoNomeDoJogador_ConexaoRemota.getText(), campoIPDoServidor_ConexaoRemota.getText());
//GEN-LAST:event_botaoConectar_ConexaoRemotaActionPerformed
//---------------------------------------------------------
//    try{
//    
//    IU_Ranking.getIU_Ranking().exibirTela(new HashMap<String,Integer>());
//    }catch(Exception e){}
}                                                           

    /**
    * @param args the command line arguments
    */
//    public static void main(String args[]) {
//        java.awt.EventQueue.invokeLater(new Runnable() {
//            public void run() {
//                new IU_ConexaoRemota().setVisible(true);
//            }
//        });
//    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton botaoConectar_ConexaoRemota;
    private javax.swing.JButton botaoSair_ConexaoRemota;
    private javax.swing.JTextField campoIPDoServidor_ConexaoRemota;
    private javax.swing.JTextField campoNomeDoJogador_ConexaoRemota;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    // End of variables declaration//GEN-END:variables

}
